package guava.basic;

import com.google.common.base.Throwables;
import com.google.common.collect.EvictingQueue;
import org.junit.Test;

import java.util.Arrays;
import java.util.StringJoiner;

/**
 * @author jiangwz
 * @create 2021/9/26.
 */
public class BasicTest {

    /**
     * -Xms10m -Xmx10m -XX:+PrintGCDetails
     */
    public static void main(String[] args) {
        EvictingQueue<Integer> queue = EvictingQueue.create(Integer.MAX_VALUE);
        for (int i = 0; i < Integer.MAX_VALUE; i++) {
//        for (int i = 0; i < 10; i++) {
            queue.offer(i);
            System.out.println(String.format("当前队列大小：%s",queue.size()));
        }
    }
    /**
     * -Xms10m -Xmx10m -XX:+PrintGCDetails
     */
    @Test
    public void testEvictingQueue(){
        EvictingQueue<byte[]> queue = EvictingQueue.create(3000);
        for (int i = 0; i < 10000; i++) {
            byte[] bytes = new byte[1024 * 1024];
            queue.offer(bytes);
            System.out.println(String.format("当前队列大小：%s",queue.size()));
        }
    }
    @Test
    public void testEvictingQueue02(){

        EvictingQueue<Integer> queue = EvictingQueue.create(3000);
        for (int i = 0; i < 100000000; i++) {
            queue.offer(i);
            System.out.println(String.format("当前队列大小：%s",queue.size()));
        }
    }

    @Test
    public void test01() {
        try {
            methodA();
        } catch (Exception e) {
            Throwable rootCause = Throwables.getRootCause(e);
            rootCause.printStackTrace();
        }
    }

    void methodA() {
        methodB();
    }

    void methodB() {
        methodC();
    }

    void methodC() {
        throw new NullPointerException();
    }

}
